﻿namespace Ngs
{
    using System;
    using System.Globalization;

    /// <summary>
    /// Data structure for modeling object pairs.
    /// </summary>
    /// <typeparam name="TFirst"></typeparam>
    /// <typeparam name="TSecond"></typeparam>
    public class Pair<TFirst, TSecond> : IEquatable<Pair<TFirst, TSecond>>
    {
        public Pair()
        {
        }

        public TFirst First { get; set; }

        public TSecond Second { get; set; }

        #region Object Method Overrides

        public bool Equals(Pair<TFirst, TSecond> pair)
        {
            if (pair == null)
            {
                return false;
            }
            if (!((this.First != null) ? this.First.Equals(pair.First) : (pair.First == null)))
            {
                return false;
            }
            if (this.Second == null)
            {
                return (pair.Second == null);
            }
            return this.Second.Equals(pair.Second);
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }
            Pair<TFirst, TSecond> pair = obj as Pair<TFirst, TSecond>;

            return this.Equals(pair);
        }

        public override int GetHashCode()
        {
            int num = (this.First == null) ? 1 : (this.First.GetHashCode() + 1);
            int num2 = (this.Second == null) ? 1 : (this.Second.GetHashCode() + 1);
            return (num * num2);
        }

        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentCulture, "Pair<{0},{1}>", new object[] { (this.First != null) ? this.First.ToString() : "null", (this.Second != null) ? this.Second.ToString() : "null" });
        }
        #endregion
    }
}
